package com.imooc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author: ldk
 * 描述: TODO
 */
@Configuration //配置声明
@EnableSwagger2  //自动配置Swagger2
public class Swagger2 {
    @Bean  //在配置上添加@Bean ，否则配置无法生效，加上后Spring才知道他是一个Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2) //指定api 类型为swagger2
                    .apiInfo(apiInfo())                          //用于定义api文档汇总信息,定义一些基本信息
                    .select()   //返回一个APISelectorBuilder实例，用来控制那些接口暴露给Swagger来展现
                    .apis(RequestHandlerSelectors
                            .basePackage("com.imooc.controller")) //指定controller包
                    .paths(PathSelectors.any())         //所有controller
                    .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("天天吃货 电商平台接口")   // 文档页标题
                .contact(new Contact("刘东奎",
                        "liudongkui.ys168.com",
                        "danxuemeixiang@163.com"))  //联系人信息
                .description("转为天天吃货提供的api文档")      //详细信息
                .termsOfServiceUrl("http:www.imooc.com")   //网站地址
                .version("1.0.2")                          //文档版本号
                .build();
    }

}
